package com.numbfish.ch_06.ExecutorCompletionService_4.src.test ;

import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.numbfish.ch_06.ExecutorCompletionService_4.src.myrunnable.MyRunnable;
import com.numbfish.ch_06.ExecutorCompletionService_4.src.entity.Userinfo;

public class Run1 {

	public static void main(String[] args) {
		try {
			Userinfo userinfo = new Userinfo();
			MyRunnable myRunnable = new MyRunnable(userinfo);

			Executor executor = Executors.newCachedThreadPool();
			CompletionService csRef = new ExecutorCompletionService(executor);

			Future<Userinfo> future = csRef.submit(myRunnable, userinfo);
			System.out.println(future.get().getUsername() + " "
					+ future.get().getPassword());

		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}